<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html>
<head>
	<meta charset="utf-8">
	<title>添加成员</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/public.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/topdiv.css" media="all" />
	<style type="text/css">
	.layui-col-xs12 {
    width: 80%;
    }
    .layui-form-select {
     position: relative;
   	 width: 275px;
     }
    .layui-input, .layui-textarea {
    display: block;
    width: 275px;
    padding-left: 10px;
	}
}
	</style>
</head>
<body class="childrenBody">
<div class="bread">
	<ul><li> 当前位置&nbsp;:</li><li>账号列表</li>&gt;<li><c:if test="${sysUser.userId == null}">添加账号</c:if><c:if test="${sysUser.userId != null}">修改账号</c:if></li></ul>
</div>
<br><br>
<form class="layui-form" style="width:80%;">
	<input type="hidden" id="id" name="id" value="${sysUser.userId}" />
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>姓名:</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input userName" lay-verify="required" placeholder="请输入姓名" value="${sysUser.userName}">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>账号:</label>
		<div class="layui-input-block">
		   <c:if test="${sysUser.userId != null}">
		   		<input type="text" class="layui-input userId layui-disabled" disabled id="userId" lay-verify="required" placeholder="请输入账号" value="${sysUser.userId}">
		   </c:if>
		   <c:if test="${sysUser.userId == null}">
		   		<input type="text" class="layui-input userId" id="userId" lay-verify="required" placeholder="请输入账号" value="${sysUser.userId}">
		   </c:if>
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>密码:</label>
		<div class="layui-input-block">
			<input type="password" class="layui-input password" lay-verify="required" placeholder="请输入密码" value="${sysUser.password}">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>角色:</label>
		<div class="layui-input-block newsStatus">
			<select name="roleId" lay-verify="required">
				<option value="">请选择</option>
						<c:forEach items="${list}" var="l">
						  <c:if test="${sysUser.roleId ==  l.roleId}">
						     <option value="${l.roleId}" selected="selected">${l.roleName}</option>
						  </c:if>
						  <c:if test="${sysUser.roleId !=  l.roleId}">
						     <option value="${l.roleId}">${l.roleName}</option>
						  </c:if>
				</c:forEach>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>状态:</label>
		<div class="layui-input-block newsStatus">
			<select name="status" lay-verify="required">
					<c:if test="${sysUser.status == 0}">
					    <option selected="selected" value="0">启用</option>
					    <option value="1">停用</option>
					</c:if>
					<c:if test="${sysUser.status == 1}">
					    <option value="0">启用</option>
					    <option selected="selected" value="1">停用</option>
					</c:if>
					<c:if test="${sysUser.status == null}">
					    <option value="0">启用</option>
					    <option value="1">停用</option>
					</c:if>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="addUser">提交</button>	
			<%-- <c:if test="${users != null}">
	    	   <button type="reset" class="layui-btn layui-btn-primary" onclick="close_self();">取消</button>
	        </c:if> --%>
	        <button type="reset" class="layui-btn layui-btn-primary" onclick="close_self();">返回</button>
		</div>
	</div>
</form>
<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
<script src="${webroot}/static/js/jquery-3.2.1.min.js" charset="utf-8"></script>
<script>
layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;
    
    form.on("submit(addUser)",function(data){
    	var url = "";
    	if ($("#id").val() != null && $("#id").val()  !="") {
    		url='${webroot}/sysuser/update';
    	}else{
    		url='${webroot}/sysuser/insert';
    	}
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        $.post(url,{
             userName : $(".userName").val(),  //登录名
             userId: $(".userId").val(),  
             roleId : data.field.roleId,
             password : $(".password").val(),
             status : data.field.status
         },function(res){
        	 var data=JSON.parse(res);
        	 if(data.success){
        		top.layer.close(index);
  	            top.layer.msg("操作成功");
        		 setTimeout(function(){window.location.href="${webroot}/sysuser/showlist?id=${resourceId}";},2000); 
        	 }else{
        		 top.layer.msg(data.message);
        	 }
        })
        return false;
    })

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());
})
function close_self(){
	window.location.href='${webroot}/sysuser/showlist?id=${resourceId}';
}
</script>
</body>
</html>